{% extends "mall/base.html" %}

{% block title %}
    商城
{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{{ STATIC_URL }}/static/css/mall/mall.css?v={{ version_code }}">
    <script type="text/javascript">
        window.onload = function () {
            if(window.name != "mall"){
                location.reload();
                window.name = 'mall';
            }else{
                window.name = "";
            }
        }
    </script>
{% endblock %}

{% block header %}
{% endblock %}

{% block content %}
    <input type="hidden" name="open_id" value="{{ open_id }}">

    {#    <div id="topsearchbar">#}
    {#        <div class="mod_searchbar  fixed type_cate skin_1">#}
    {#            <div class="mod_searchbar_inner"><i class="mod_searchbar_cate icon_cate" id="__cate" ptag="137571.2.1"></i>#}
    {#                <form class="mod_searchbar_form " onsubmit="return false;">#}
    {#                    <input type="search" id="topSearchTxt"#}
    {#                           class="mod_searchbar_text"#}
    {#                           placeholder="搜索喜欢的商品"#}
    {#                           autocomplete="off"><i#}
    {#                        class="mod_searchbar_clear" id="topSearchClear"></i></form>#}
    {#                <span class="mod_searchbar_btn bg_1"#}
    {#                      id="topSearchbtn"#}
    {#                      style="display:none;">搜索</span></div>#}
    {#        </div>#}
    {#    </div>#}
    <div class="search_prolist cols_1" id="itemList">

        {% for foo in goods_array %}
            <div class="search_prolist_item" data-link="/mall/detail/{{ foo.sdef_goods_id }}">
                <div class="search_prolist_item_inner">
                    <div class="search_prolist_cover">
                        <img class="photo" src="{{ foo.sdef_goods_thumbnail|json_loads|get_item(0) }}">
                    </div>
                    <div class="search_prolist_info">
                        <div class="search_prolist_title">
                            {{ foo.sdef_goods_name }}
                        </div>
                        <div class="search_prolist_price">
                            <strong>
                                <em>¥ <span class="int">{{ foo.sdef_goods_price }}</span></em>
                            </strong>
                        </div>
                        <div class="search_prolist_line">
                        </div>
                        {% if is_membership %}
                        <div class="search_prolist_other text_small">
                            <span class="search_prolist_rate">会员¥<span>{{ foo.sdef_goods_member_price }}</span></span>
                            <!-- <span class="search_prolist_comment"><span>库存</span> {{ foo.sdef_goods_count }}</span> -->
                        </div>
                        {% endif %}
                        {% if foo.sdef_goods_count <= 0 %}
                        <div class="search_prolist_buy color_red no_count" data-id="{{ foo.sdef_goods_id }}">
                        </div>
                        {% elif foo.sdef_goods_count > 0 %}
                        <div class="search_prolist_buy color_red have_count" data-id="{{ foo.sdef_goods_id }}">
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        {% endfor %}
        <div id="J-cart-flow-icon" class="u-shopbag add-bottom"
             style="bottom: 19.2px; visibility: visible;">
            <a href="/cart">
                <span class="icon-cart i-flow-carticon" id="cartCount">{{ cart_count }}</span>
                <span class="u-flow-cartnum J-cart-num"></span>
                <span class="u-flow-carttime" id="J-cart-time"></span>
            </a>
        </div>
    </div>

{% endblock %}

{% block footer %}
{% endblock %}

{% block js %}
    <script src="{{ STATIC_URL }}/static/js/mall/mall.js?v={{ version_code }}"></script>

    {% if is_wechat %}
        <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
        <script>
            var debug = false;
            var appId = "{{ app_id }}";
            // 时间戳
            var timeStamp = "{{ time_stamp }}";
            // 随机字符串
            var nonceStr = "{{ nonce_str }}";
            var signature = "{{ signature }}";
            var link = "https://" + location.host + "/mall?oid=" + $("input[name=open_id]").val();

            $(function () {
                wx.config({
                    debug: debug, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: appId, // 必填，公众号的唯一标识
                    timestamp: timeStamp, // 必填，生成签名的时间戳
                    nonceStr: nonceStr, // 必填，生成签名的随机串
                    signature: signature,// 必填，签名，见附录1
                    jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });
                wx.ready(function () {
                    wx.onMenuShareTimeline({
                        title: '同样的红酒为什么到了国内，变得又贵又不好喝？', // 分享标题
                        link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: 'http://wx.style999.com/static/img/logo.png?v={{ version_code }}', // 分享图标
                        success: function () {
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    });
                    wx.onMenuShareAppMessage({
                        title: '同样的红酒为什么到了国内，变得又贵又不好喝？', // 分享标题
                        desc: '无论再好的红酒，在30°环境下超过18小时，它的色、香、味、口感都会造成不可逆转的致命性伤害。', // 分享描述
                        link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: 'http://wx.style999.com/static/img/logo.png?v={{ version_code }}', // 分享图标
                        type: 'link', // 分享类型,music、video或link，不填默认为link
                        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                        success: function () {
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    });
                });
                wx.error(function (res) {
                    alert("调用错误");
                    alert(JSON.stringify(res));
                });

                function showDebug(k, v) {
                    // 显示调试信息
                    var html = "<p>";
                    html += k + ":" + v;
                    html += "</p>";
                    $("#debug").append(html);
                }

                if (debug) {
                    showDebug("appid", appId);
                    showDebug("timeStamp", timeStamp);
                    showDebug("nonceStr", nonceStr);
                    showDebug("signature", signature);
                }
            })
        </script>
    {% endif %}
{% endblock %}